<template>
  <rx-dialog @handOk="transfer" @cancel="closeWindow" :oktext="$ti18('rxForm.commitBtn','提交')" order="buttom" btnalign="center">
    <rx-fit>
      <div style="height:100%;width:100%;padding:20px;">
      <a-form-model :model="form">
        <a-form-model-item :label="i18n('forwardList.forward','抄送人')" :label-col="labelCol" :wrapper-col="wrapperCol" v-if="send" >
          <rx-user-component v-model="copyUsers" :isAccount="false" :single="false"></rx-user-component>
        </a-form-model-item>
        <a-form-model-item :label="i18n('forwardList.opinion','意见')" :label-col="labelCol" :wrapper-col="wrapperCol" >
          <a-textarea v-model="form.opinion"></a-textarea>
        </a-form-model-item>
      </a-form-model>
    </div>
  </rx-fit>
  </rx-dialog>
</template>
<script>

import { Dialog, RxDialog, Util, RxFit, RxUserComponent,RxAttachComponent,RxTextList} from '@lowcode/jpaas-common-lib';
import BpmPublicApi from '@/api/bpm/core/BpmPublicApi';
import BpmInstCcApi from '@/api/bpm/core/bpmInstCc';

export default {
  name: 'bpm-task-transfer',
  components: {
      RxUserComponent,
      RxAttachComponent,
      RxFit,
      RxDialog,
      RxTextList
  },
  props: {
    layerid: String,
    lydata: Object,
    destroy: Function,
    instId:String,
    send:{
        type: Boolean,
        default:true
    }

  },
  data() {
    return {

      labelCol: { span: 4 },
      wrapperCol: { span: 8 },
      msgOptions:[],

      copyUsers:[],
      files:[],
      msgTypes:[],
      form:{
          copyUsers:"",
          files:"[]",
          msgTypes:"",
          opinion:"",
          send:this.send,
          instId:this.instId
      }
    }
  },
  created(){
      this.initMessageHandler();
  },
  methods: {
    i18n(name,text,key){
        return this.$ti18(name,text,"MyApprovedTasks",key);
    },
    initMessageHandler(){
        BpmPublicApi.getMessageHandler().then(res=>{
            for(var i=0;i<res.length;i++){
                var o=res[i];
                var obj={ label: o.name, value: o.type };
                this.msgOptions.push(obj);
            }
        })
    },
    transfer(){
        if(this.form.send){
            if(this.copyUsers.length==0){
                this.$message.warning(this.i18n('msa.selectExecutorTips','请选择执行人!'));
                return;
            }
        }



        this.form.copyUsers=JSON.stringify(this.copyUsers);
        this.form.files=JSON.stringify(this.files);
        this.form.msgTypes=JSON.stringify(this.msgTypes);

        BpmInstCcApi.transfer(this.form).then(res=>{
          if(res.success){
              Util.closeWindow(this, 'ok');
          }
        });
    },
    closeWindow() {
        Util.closeWindow(this, 'cancel')
    },

  }
}
</script>